<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <!-- 主表单区域 -->
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="8" >
            <a-form-model-item label="时间" :labelCol="{ span: 6 }" :wrapperCol="{ span: 18 }" prop="date">
              <g-year-picker
                placeholder="请选择时间"
                v-model="model.date"
              ></g-year-picker>
            </a-form-model-item>
          </a-col>
          <a-col :span="8" >
            <a-form-model-item label="级别" :labelCol="{ span: 6 }" :wrapperCol="{ span: 18 }" prop="classess">
              <j-dict-select-tag type="list" v-model="model.classess" dictCode="RESEARCH_ZXKYXM_CLASSESS" placeholder="请选择级别" @change="getTotalScore"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8" >
            <a-form-model-item label="类别" :labelCol="{ span: 6 }" :wrapperCol="{ span: 18 }" prop="category">
              <j-dict-select-tag type="list" v-model="model.category" dictCode="RESEARCH_ZXKYXM_CATEGORY" placeholder="请选择类别" @change="getTotalScore"/>
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="8" >
            <a-form-model-item label="阶段" :labelCol="{ span: 6 }" :wrapperCol="{ span: 18 }" prop="step">
              <j-dict-select-tag type="list" v-model="model.step" dictCode="RESEARCH_ZXKYXM_STEP" placeholder="请选择阶段" @change="getTotalScore"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8" >
            <a-form-model-item label="总分" :labelCol="{ span: 6 }" :wrapperCol="{ span: 18 }" prop="totalScore">
              <a-input v-model="model.totalScore" placeholder="请输入总分" ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="24" >
            <a-form-model-item label="项目名称" :labelCol="{ span: 2 }" :wrapperCol="{ span: 22 }" prop="projectName">
              <a-input v-model="model.projectName" placeholder="请输入名称" ></a-input>
            </a-form-model-item>
          </a-col>

          <a-col :span="24" >
            <a-form-model-item label="备注" :labelCol="{ span: 2 }" :wrapperCol="{ span: 22 }" prop="remark">
              <a-input  v-model="model.remark" placeholder="请输入备注" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
    <research-member-list ref="memberListRef" v-model="memberListTable.dataSource" :project-info="model"  :disabled="formDisabled" :loading="memberListTable.loading"></research-member-list>
  </a-spin>
</template>

<script>

  import { GfxyResearchMemberListMixin } from '@/mixins/GfxyResearchMemberListMixin'
  import researchMemberList from '@views/gfxy/common/researchMemberList'
  import GYearPicker from '@views/gfxy/common/GYearPicker'
  import { getAction } from '@api/manage'

  export default {
    name: 'ResearchZxkyxmForm',
    mixins: [GfxyResearchMemberListMixin],
    components: {
      GYearPicker,researchMemberList
    },
    data() {
      return {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 6 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        labelCol2: {
          xs: { span: 24 },
          sm: { span: 3 },
        },
        wrapperCol2: {
          xs: { span: 24 },
          sm: { span: 20 },
        },


        validatorRules: {
          date: [
            { required: true, message: '请输入时间!'},
          ],
          classess: [
            { required: true, message: '请选择级别!'},
          ],
          category:[
            { required: true, message: '请选择类别!'},
          ],
          step: [
            { required: true, message: '请选择项目阶段!'},
          ],
          projectName: [
            { required: true, message: '请输入实训基地名称!'},
          ],
        },

        url: {
          add: "/research/researchZxkyxm/add",
          edit: "/research/researchZxkyxm/edit",
          queryById: "/research/researchZxkyxm/queryById",
          getTotalScore: "/research/researchZxkyxm/getTotalScore",
        }
      }
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      },
      projectType:{
        type: Number,
        required: true,
      },
      date:{
        type: String,
        required: true,
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },

    methods: {
      getTotalScore(){
        let that = this;
        if(this.model.category != undefined && this.model.classess != undefined && this.model.step != undefined){
          this.confirmLoading = true;
          getAction(this.url.getTotalScore,{category: this.model.category, classess: this.model.classess, step: this.model.step}).then((res) => {
            if (res.success) {
              this.model.totalScore = res.result;
              this.$nextTick(()=>{
                this.$refs.memberListRef.getScore();
              })
            }
            if(res.code===510){
              this.$message.warning(res.message)
            }

          }).catch(()=>{
            this.$message.warning("出错！");
          }).finally(() => {
            this.confirmLoading = false;
          })
        }
      },
    }
  }
</script>

<style scoped>
</style>